package com.leetcode.LeetCode精选TOP面试题;

/**
 * @author 覃国强
 * @date 2022-05-25 17:30
 */
public class 题库_0053_最大子数组和 {

  static
  class Solution {
    public int maxSubArray(int[] nums) {
      if (nums == null || nums.length == 0) {
        return 0;
      }
      int answer = nums[0];
      int dp = nums[0];
      for (int i = 1; i < nums.length; ++i) {
        dp = dp < 0 ? nums[i] : dp + nums[i];
        answer = Math.max(answer, dp);
      }
      return answer;
    }
  }

}
